package com.jingdianjichi.oss.adapter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 抽一层负责对方接口暴露
 */
@Service
@Slf4j
public class FileService {

    private final StorageAdapter storageAdapter;

    public FileService(StorageAdapter storageAdapter) {
        this.storageAdapter = storageAdapter;
    }


    public List<String> getAllBuckets() {
        return storageAdapter.getAllBuckets();
    }


    public String getUrl(String bucketName, String fileName) {
        return storageAdapter.getUrl(bucketName,fileName);
    }

    public String uploadFile(MultipartFile file, String bucketName, String fileName) {
        log.info("fileName:[{}]",fileName);
        storageAdapter.uploadFile(file,bucketName,fileName);
        String url = storageAdapter.getUrl(bucketName, fileName);
        return  url;
    }
}
